package com.fiona.start.base;

import java.util.Map;
import java.util.Map.Entry;

import com.fiona.common.base.config.RpcConfig;
import com.fiona.common.extension.Extension;
import com.fiona.common.extension.ExtensionLoader;
import com.fiona.core.remoting.model.FionaApiServiceObj;
import com.fiona.core.remoting.model.Service;
import com.fiona.register.api.ServiceRegister;
import com.fiona.start.IStart;

@Extension(order = 3)
public class RegistryStart implements IStart {

	@Override
	public void start(Class<?> clazz) {
		if (null != RpcConfig.getAddress()) {
			ServiceRegister registry = ExtensionLoader.getExtensionLoader(ServiceRegister.class).getExtension("zk");
			Map<String, Service> serviceMap = FionaApiServiceObj.getServiceMap();
			for (Entry<String, Service> entry : serviceMap.entrySet()) {
				try {
					registry.register(entry.getValue());
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
	}
}
